package com.cke.yang.common.domain.model;

import com.cke.yang.security.domain.entity.SecUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 用户安全上下文详情
 *
 * @author yuyang
 * @date 2025-11-18 00:00:00
 */
public class SecUserDetails implements UserDetails {

    private SecUser secUser;

    private String username;

    private String password;

    private Boolean enabled = true;

    /**
     * 当前用户选择的角色ID
     */
    private Long currentRoleId;

    /**
     * 当前用户选择的角色名称
     */
    private String currentRoleName;

    public SecUserDetails() {
    }

    public SecUserDetails(SecUser user) {
        this.secUser = user;
        this.username = user.getUsername();
        this.password = user.getPassword();
        this.enabled = user.getIsEnabled();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of();
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

    public Long getUserId() {
        return this.secUser.getUserId();
    }

    public Long getCurrentRoleId() {
        return this.currentRoleId;
    }

    public void setCurrentRoleId(Long currentRoleId) {
        this.currentRoleId = currentRoleId;
    }

    public String getCurrentRoleName() {
        return this.currentRoleName;
    }

    public void setCurrentRoleName(String currentRoleName) {
        this.currentRoleName = currentRoleName;
    }

}
